function success(msg) {
    layer.msg(msg, {icon: 1});
}

function successUp(msg) {
    parent.layer.msg(msg, {icon: 1});
}

function error(msg) {
    layer.msg(msg, {icon: 2});
}

function load(num) {
    if (!num) {
        num = 1;
    }
    var index = layer.load(num, {
        shade: [0.3, "#000"] //0.3透明度的白色背景
    });
    return index;
    console.log(index);
}

function parseToDate(value) {
    if (value == null || value == "") {
        return undefined;
    }
    var dt;
    if (value instanceof Date) {
        dt = value;
    } else {
        if (!isNaN(value)) {
            dt = new Date(value);
        } else if (value.indexOf("/Date") > -1) {
            value = value.replace(/\/Date\((-?\d+)\)\//, "$1");
            dt = new Date();
            dt.setTime(value);
        } else if (value.indexOf("/") > -1) {
            dt = new Date(Date.parse(value.replace(/-/g, "/")));
        } else {
            dt = new Date(value);
        }
    }
    return dt;
}

Date.prototype.format = function (format) {// author: meizz
    var o = {
        "M+": this.getMonth() + 1, // month
        "d+": this.getDate(), // day
        "h+": this.getHours(), // hour
        "m+": this.getMinutes(), // minute
        "s+": this.getSeconds(), // second
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
        "S": this.getMilliseconds()
        // millisecond
    };
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
            .substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

function dictTrans(type, code) {
    if (code) {
        if (dic_arr) {
            for (var i = 0; i < dic_arr.length; i++) {
                if (dic_arr[i].disCode == code && dic_arr[i].disType == type) {
                    return dic_arr[i].disCodeName;
                }
            }
            return code;
        }
    }
    return "";
}

function xiehuiTrans(value) {
    if (value) {
        if (xiehui_arr) {
            for (var i = 0; i < xiehui_arr.length; i++) {
                if (xiehui_arr[i].assId == value ) {
                    return xiehui_arr[i].assName;
                }
            }
            return value;
        }
    }
    return "";
}

function enumTrans(type, value) {
    if (value) {
        if (enums) {
            var datas = enums[type];
            for (var i = 0; i < datas.length; i++) {
                if (value == datas[i].key) {
                    return datas[i].value;
                }
            }
        }
    }
    return "";
}

function compartmentMinor(compartment) {
    if (compartment) {
        if (compartment_arr) {
            var compartments = new Array();
            for (var i = 0; i < compartment_arr.length; i++) {
                if (compartment == compartment_arr[i].main) {
                    compartments.push(compartment_arr[i].minor);
                }
            }
            return compartments;
        }
    }
    return "";
}

function verificationData(type, value) {
    var isExist = false;
    if (value) {
        $.ajax({
            async: false,
            type: "post",
            url: ctx + "isExist",
            data: {
                type: type,
                value: value
            },
            dataType: "json",
            success: function (data) {
                if (data) {
                    isExist = true;
                }
            }
        });
    }
    return isExist;
}

function isNumber(val) {
    var regPos = /^\d+(\.\d+)?$/; //非负浮点数
    var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
    if (regPos.test(val) || regNeg.test(val)) {
        return true;
    } else {
        return false;
    }
}

function deleteFile(filePath) {
    $.ajax({
        async: true,
        url: ctx + "deleteFile",
        data: {
            filePath: filePath
        },
        type: "post",
        dataType: "json"
    });
}

//关闭当前layui弹框
function closeDialog() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

function parentTableReload(id) {
    parent.layui.table.reload(id);
}
